package edu.hawaii.halealohacli.command;

import static org.junit.Assert.assertTrue;
import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;
import org.wattdepot.util.tstamp.Tstamp;

/**
 * A JUnit test class for the Command "Daily Energy".
 * 
 * @author Russell Vea.
 * @author David Wilkie.
 * @author Yong Hong Hsu.
 * @author Branden Ogata
 */
public class TestDailyEnergy {

  private DailyEnergy daily = new DailyEnergy();

  /**
   * Tests the DailyEnergy class.
   * The test goes through the following procedure:
   * 1.  Creates a timestamp of yesterday.
   * 2.  Gets the second source from the list of sources.
   * 3.  Passes them to DailyEnergy.printResults() like how Processor would.
   * 
   * @throws Exception when there's an error with the server.
   */
  @Test public void test() throws Exception {
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    Source testSource = client.getSources().get(1);
    
    // Creates a timestamp for the test
    XMLGregorianCalendar testTimestamp = Tstamp.makeTimestamp();
    testTimestamp = Tstamp.incrementDays(testTimestamp, -1);
    testTimestamp.setHour(0);
    testTimestamp.setMinute(0);
    testTimestamp.setSecond(0);
    testTimestamp.setMillisecond(0);
    
    // Prints the results for a manual test
    daily.printResults(client, testSource, testTimestamp);

    // Tests validity of output
    assertTrue("Test to see if energy was greater than zero.", daily.getEnergy() > 0.0);
  }
}
